-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added "ACL LOG" command new in Redis 6 RC2 #1307
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1307 +/- ##
=========================================
+ Coverage 92.81% 92.9% +0.09%
=========================================
Files 19 19
Lines 6526 6583 +57
=========================================
+ Hits 6057 6116 +59
+ Misses 469 467 -2
Continue to review full report at Codecov.
|
I skimmed the code and this initially looks well done. Thanks! Is there any documentation for |
It has yet to be documented |
Yes the ACL doc is not updated. |
The return type may change to boolean, base on what argument is used. I am thinking about splitting them into two methods like `acl_log()` and `acl_log_reset()`. But that will not match the Redis command usage which is `ACL LOG [<count> | RESET]`.
The return type may change from list to boolean, based on what argument is used. I am thinking about splitting them into two methods like |
Hi. Any idea about this one? @andymccurdy |
Hi @2014BDuck, great work! Also note you can drop the commit to change redis version in travis, as we are now using version 6.0.5 on master. |
|
Codecov Report
@@ Coverage Diff @@
## master #1307 +/- ##
==========================================
- Coverage 92.76% 85.76% -7.01%
==========================================
Files 20 7 -13
Lines 6581 3049 -3532
==========================================
- Hits 6105 2615 -3490
+ Misses 476 434 -42
Continue to review full report at Codecov.
|
@2014BDuck Awesome, thanks. Ping me when you get this split into two separate functions and we'll get it merged. |
@andymccurdy Hi ptal one more time. Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really close. Thanks for splitting up the command. A few inline notes below and then we'll get this merged. Thanks!
tests/test_commands.py
Outdated
r_test.set("cache:0", 1) | ||
r_test.get("cache:0") | ||
# Invalid key | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be:
with pytest.raises(exceptions.NoPermissionError):
r_test.get('violated_cache:0')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks.
tests/test_commands.py
Outdated
except exceptions.NoPermissionError: | ||
pass | ||
# Invalid operation | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above:
with pytest.raises(exceptions.NoPermissionError):
r_test.hset('cache:0', 'hkey', 'hval')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks.
pass | ||
|
||
assert len(r.acl_log()) == 2 | ||
assert len(r.acl_log(count=1)) == 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to assert that acl_log()
returns a dict
and that a common set of keys exist. Additionally we should check that the 'click-info' value is a dict
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added few return type assertion now.
tests/test_commands.py
Outdated
keys=['cache:*'], nopass=True) | ||
r.acl_log_reset() | ||
|
||
r_test = redis.Redis(host='localhost', port=6379, db=9, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to hardcode connection info in a test. Instead, use the _get_client
function from conftest.py
. Something like:
r_test = _get_client(redis.Redis, request, username=username)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep please check the comment below
Hi @andymccurdy For the hardcoded connection:
Yep it's not pretty. I tried to find out the correct pattern to new a different client before writting it but haven't found any example. The get_client way # This method passed redus_url string grabbed from request obj. And passed to "from_url" class method.
def _get_client(cls, request, single_connection_client=True, **kwargs):
redis_url = request.config.getoption("--redis-url")
client = cls.from_url(redis_url, **kwargs)
.....
# This method will parse url and use the username in url.
def from_url(cls, url, db=None, decode_components=False, **kwargs):
url = urlparse(url)
url_options = {}
...
# Here. The username is token directly from the url we passed in.
if decode_components:
username = unquote(url.username) if url.username else None
...
else:
username = url.username or None
... So it's not working using
Actually both of them sound worse from my point of view. Would like to hear more advice from your side. Many thanks. |
@andymccurdy Hi. May I request for a review and your suggestion again? Two things after I merged the current master branch.
|
@2014BDuck I fixed this in the acl-log branch here: https://github.com/andymccurdy/redis-py/tree/acl-log I believe that branch is good to go. Let me know if you see anything off. If you want to merge it back into this PR I'll then merge your PR to master. Alternatively I can just merge the acl-log branch to master. Let me know what you prefer. |
@andymccurdy Yes please. And sorry for wasting your time and effort on guiding. Very appreciated. |
Merged. Thanks! |
Pull Request check-list
Please make sure to review and check all of these items:
$ tox
pass with this change (including linting)?NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.
Description of change
Hi. First of all thanks for checking this.
There is an "ACL LOG" command added in Redis 6 RC2. I tried to add it to redis-py.
The "ACL LOG" command supports two kind of arguments:
ACL LOG [<count> | RESET]
. For<count>
, it returns a acl log list. ForRESET
, it returns 'OK'. So I parsed it into:Note that the wget link in
.travis.yml
is changed as well since the RC1 does not have aLOG
sub-command forACL
.Please take a look. It's my first PR for open-source project. Thank you.